//
//  FTBaseNavigationController.m
//  FashionTech
//
//  Created by JackieYip on 16/4/11.
//  Copyright © 2016年 mondial-d. All rights reserved.
//

#import "FTBaseNavigationController.h"
#import "FTInternationalization_Macro.h"

@interface FTBaseNavigationController () <UINavigationControllerDelegate>
@property (assign, nonatomic, readwrite) FTTabIndex tabIndex;
@property (strong, nonatomic, readwrite) id UINavigatioInteractiveTransitionBackup;
@end

@implementation FTBaseNavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.UINavigatioInteractiveTransitionBackup = self.interactivePopGestureRecognizer.delegate;
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.delegate = self;
    _tabIndex = FTTabIndex_invalid;
    self.UINavigatioInteractiveTransitionBackup = self.interactivePopGestureRecognizer.delegate;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] init];
    barButtonItem.title = FTLocalizedStringInLocalizable(@"返回");
    viewController.navigationItem.backBarButtonItem = barButtonItem;
    
    if (_tabIndex != FTTabIndex_invalid) {
        self.tabBarController.selectedIndex = _tabIndex;
        _tabIndex = FTTabIndex_invalid;
    }
    if (![self.interactivePopGestureRecognizer.delegate isKindOfClass:[viewController class]])
        self.interactivePopGestureRecognizer.delegate = self.UINavigatioInteractiveTransitionBackup;
}

- (void)setTabIndex:(FTTabIndex)index
{
    _tabIndex = index;
}
@end
